package thread.syn;

/**
 * @Author: ycy
 * @CreateDate: 2019/5/23 20:43
 */
public class ConstructionThreadDemo {

  int i;

  int count;

  ConstructionThreadDemo c;

  public ConstructionThreadDemo() {
    i = 22;
  }

  public void product() {
    c = new ConstructionThreadDemo();
    count++;
  }

  public void read() {
    if (this.c.i == 0) {
      System.out.println("i值为0");
    }
  }


  public static void main(String[] args) {

    ConstructionThreadDemo work = new ConstructionThreadDemo();

    Thread thread1 = new Thread(new Runnable() {
      @Override
      public void run() {
        while (true) {
          work.product();
          if (work.count % 10000 == 0) {
            System.out.println(work.count);
          }
        }
      }
    });
    thread1.start();

    Thread thread2 = new Thread(new Runnable() {
      @Override
      public void run() {
        while (true) {
          work.read();
        }
      }
    });
    thread2.start();
  }

}
